using System.Collections;
using UnityEngine;

public class OnChargeObj : SynchronizedGameObject
{
	protected delegate IEnumerator WaitFunction();

	public float speed;

	public float lifeTime;

	protected float damage;

	public DamageModifications damageModifications;

	protected WaitFunction wait;

	protected Vector3 start;

	protected Vector3 end;

	protected float traveledDistance;

	public float afterHitEffectLifeTime;

	public GameObject explosionEffect;

	public GameObject afterHitEffectCar;

	public GameObject afterHitEffectNoCar;

	public Collider ignoreCollider;

	public Collider[] ignoreColliders;

	public override void OnEnable()
	{
		TrailRenderer component = GetComponent<TrailRenderer>();
		if (component != null && !settings.offlineMode && base.photonView != null && !base.photonView.isMine)
		{
			component.enabled = false;
		}
	}

	public virtual void InitCharge(Vector3 startPoint, Vector3 endPoint, float damage, Collider ignoreCollider)
	{
		DamageModifications damageModifications = this.damageModifications;
		if (damageModifications != 0 && damageModifications == DamageModifications.Level)
		{
			damage *= CupsManager.CurrentLeagueInfo.consumableDamagPercent;
		}
		start = startPoint;
		end = endPoint;
		wait = UpdateCharge;
		StartCoroutine(wait());
		this.ignoreCollider = ignoreCollider;
		this.damage = damage;
	}

	public virtual void InitCharge(Vector3 startPoint, Vector3 endPoint, float damage, Collider[] ignoreColliders)
	{
		InitCharge(startPoint, endPoint, damage, ignoreColliders[0]);
		this.ignoreColliders = ignoreColliders;
	}

	public virtual IEnumerator UpdateCharge()
	{
		yield break;
	}

	protected virtual void OnDestroy()
	{
		if (explosionEffect != null && (bool)explosionEffect)
		{
			Vector3 normalized = (start - end).normalized;
			if (normalized == Vector3.zero)
			{
				normalized = base.transform.forward;
			}
			GameObject gameObject = (GameObject)Object.Instantiate(explosionEffect, base.transform.position, base.transform.rotation);
			TriggerEffectBuffer component = gameObject.GetComponent<TriggerEffectBuffer>();
			if (component != null && !settings.offlineMode)
			{
				component.team = GameController.instance.FindPlayer(base.photonView.ownerId).localTeam;
				component.isMine = base.photonView.isMine;
			}
			Object.Destroy(gameObject, afterHitEffectLifeTime);
		}
	}

	public virtual IEnumerator CalculateTravelDistance(float maxDistance)
	{
		Vector3 startPosition = base.gameObject.transform.position;
		Vector3 currentPosition2 = base.gameObject.transform.position;
		while (traveledDistance < maxDistance)
		{
			currentPosition2 = base.gameObject.transform.position;
			traveledDistance = Vector3.Distance(startPosition, currentPosition2);
			yield return new WaitForEndOfFrame();
		}
	}
}
